package com.xkdx.guangguang.adapter;



import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.xkdx.caipiao.R;
import com.xkdx.guangguang.module.statics.IConstants;
import com.xkdx.guangguang.shareclass.DiscountInfo;

public class ShopInfoNewsInfoAdapter extends BaseAdapter {
	List<DiscountInfo> list;
	Context context;
	ImageLoader imageLoader;
	DisplayImageOptions options = new DisplayImageOptions.Builder().showStubImage(R.drawable.shop_empty)
				.showImageForEmptyUri(R.drawable.shop_empty).showImageOnFail(R.drawable.shop_empty)
				.resetViewBeforeLoading().cacheOnDisc().imageScaleType(ImageScaleType.EXACTLY)
				.bitmapConfig(Bitmap.Config.RGB_565).build();

	public ShopInfoNewsInfoAdapter(Context context, List<DiscountInfo> list,ImageLoader imageLoader) {
		this.list = list;
		this.context = context;
		this.imageLoader=imageLoader;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHodler viewHoder;

		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(R.layout.shop_new_product_item, null);
			viewHoder = new ViewHodler();
			viewHoder.image = (ImageView) convertView.findViewById(R.id.shop_new_product_image);
			viewHoder.name = (TextView) convertView.findViewById(R.id.shop_new_product_tv);
			viewHoder.time = (TextView) convertView.findViewById(R.id.time);
			convertView.setTag(viewHoder);
		} else {
			viewHoder = (ViewHodler) convertView.getTag();
		}
		String url = IConstants.addSuffix(list.get(position).getPictrueUrl(), "_cover1");
		viewHoder.name.setText(list.get(position).getInfoTitle());
		imageLoader.displayImage(url, viewHoder.image, options);
		viewHoder.time.setText(list.get(position).getBeginTime());

		return convertView;
	}

	class ViewHodler {
		TextView name, time;
		ImageView image;

	}
}